package com.dk.controller;


import com.dk.service.AutoCodeRuleService;
import com.dk.vo.AutoCodeRuleVO;
import com.dongdongshop.data.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 编码生成规则表 前端控制器
 * </p>
 *
 * @author wbh
 * @since 2023-03-18
 */
@RestController
@RequestMapping("autoCodeRule")
public class AutoCodeRuleController {
    @Autowired
    private AutoCodeRuleService autoCodeRuleService;

    //先去查询所有的规则
    //模糊查询 规则名称,规则编码,启用状态查询
    @GetMapping("getInfoListByTrim")
    public Result getInfoListByTrim(AutoCodeRuleVO autoCodeRuleVO) {
        List<AutoCodeRuleVO> autoCodeRuleVOS = autoCodeRuleService.getInfoListByTrim(autoCodeRuleVO);
        return Result.OK().setData(autoCodeRuleVOS);
    }

    @PostMapping("insertInfoAutoCodeRule")
    public Result insertInfoAutoCodeRule(AutoCodeRuleVO autoCodeRuleVO) {
        autoCodeRuleService.insertInfoAutoCodeRule(autoCodeRuleVO);
        return Result.OK();
    }

    @GetMapping("getInfoAutoCodeRuleById")
    public Result getInfoAutoCodeRuleById(Integer ruleId) {
        AutoCodeRuleVO autoCodeRuleVO = autoCodeRuleService.getInfoAutoCodeRuleById(ruleId);
        return Result.OK().setData(autoCodeRuleVO);
    }

    @PostMapping("updateInfoAutoCodeRuleById")
    public Result updateInfoAutoCodeRuleById(AutoCodeRuleVO autoCodeRuleVO) {
        autoCodeRuleService.updateInfoAutoCodeRuleById(autoCodeRuleVO);
        return Result.OK();
    }

    @PostMapping("deleteInfoAutoCodeRuleById")
    public Result deleteInfoAutoCodeRuleById(Long ruleId) {
        autoCodeRuleService.deleteInfoAutoCodeRuleById(ruleId);
        return Result.OK();
    }

    //自动生成id接口
    @PostMapping("autoGenerateEncoding")
    public Result autoGenerateEncoding(Long ruleId){
        String s = autoCodeRuleService.autoGenerateEncoding(ruleId);
        return Result.OK().setData(s);
    }

}

